//
//  LGChooseRedPacketViewController.m
//  LuxuryGoods
//
//  Created by 刘星辰 on 2018/6/15.
//  Copyright © 2018年 Future. All rights reserved.
//

#import "LGChooseRedPacketViewController.h"
#import "UIButton+Gradual.h"
#import "LGRedPacketCell.h"

@interface LGChooseRedPacketViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong)NSMutableArray *dataArray;
@property (nonatomic,strong)NSMutableArray *selectArray;
@property (nonatomic,strong)UIButton *bar;
@property (nonatomic,strong)UITableView *tableView;
@end

@implementation LGChooseRedPacketViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"选择红包";
    
    self.dataArray = [NSMutableArray array];
    self.selectArray = [NSMutableArray array];
    
    [self.view addSubview:self.bar];
    [self.bar mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(self.bar.left);
        make.right.offset(-self.bar.left);
        make.height.offset(self.bar.height);
        make.bottom.offset(-HOMEBAR_HEIGHT - 10);
    }];
    
    [self.view addSubview:self.tableView];
    [self.tableView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_offset(UIEdgeInsetsMake(0, 0, self.bar.height + HOMEBAR_HEIGHT + 10, 0));
    }];
}

#pragma mark -
#pragma mark tableView的Delegate和DataSource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 6;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *view = [UIView new];
    return view;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    return [UIView new];
}


- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 10;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return CGFLOAT_MIN;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //创建xib复用单元格
    static NSString * ID = @"LGRedPacketCell";
    LGRedPacketCell * cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"LGRedPacketCell" owner:self options:nil] firstObject];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    
    cell.selectAciton = ^(LGRedPacketCell *cell) {
        NSIndexPath *index = [tableView indexPathForCell:cell];
        if (cell.selected)
        {
            [tableView deselectRowAtIndexPath:indexPath animated:YES];
        }
        else
        {
             [tableView selectRowAtIndexPath:index animated:YES scrollPosition:UITableViewScrollPositionNone];
        }
    };
    
    return cell;
}



//实际高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 82;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

}

- (UIButton *)bar
{
    if (_bar == nil)
    {
        
        UIButton * button = [UIButton buttonWithType:UIButtonTypeSystem];
        button.frame = CGRectMake(14, 0, SCREEN_WIDTH - 14 * 2, 40);
        [button setTitle:@"确认使用" forState:UIControlStateNormal];
        [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        WeakObj(self);
        [button bk_addEventHandler:^(id sender) {
            NSLog(@"%@",selfWeak.tableView.indexPathsForSelectedRows);
        } forControlEvents:UIControlEventTouchUpInside];
      
        _bar = button;
        [button addGradualColorAndCorner];

    }
    return _bar;
}

- (UITableView *)tableView
{
    if (_tableView == nil)
    {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - NAVIGATOR_HEIGHT) style:UITableViewStyleGrouped];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.allowsMultipleSelection = YES;
        _tableView.backgroundColor = UIColorFromRGB(0xF5F5F5);
    }
    return _tableView;
}
@end
